import time

setGlobalDuration(-1)

beginPythonInst(1)
soundfont(duration=1)
endPythonInst()

proc = startCsound()

notes = '''67 69 71 74 72 72 76 74 74 79 78 79 74 71 67 69 71 72 74 76 74 72 71 69 71 67 66 67 69 \
        62 66 69 72 71 69 71 67 69 71 74 72 72 76 74 74 79 78 79 74 71 67 69 71 64 74 72 71 69 \
        67 62 67 66 67 71 74 79 74 71 67 71 74 79 62 64 66 69 67 69 72 71 72 69 66 62 66 69 72 \
        71 69 71 67 69 71 74 72 72 76 74 74 79 78 79 74 71 67 69 71 64 74 72 71 69 67 62 67 66 67'''
noteslist = [int(n) for n in notes.split()]

time.sleep(2)

mrk = markov(3)
mrk.mkSetList(noteslist)
mrk.mkStartPlayback()

mrk2 = markov(3)
mrk2.mkSetList(noteslist)
mrk2.mkStartPlayback()

# Change these values in the interpreter during performance
tempo = .125
tr1 = 12
tr2 = -12

def pit():
    if ti1.getBeat() in [1,2,3]:
        dict = {'soundfont': {}}
        dict['soundfont']['midipitch'] = mrk.next()+tr1
        sendEvent(1, dict, proc)
    if ti1.getBeat() in [1,3,4]:
        dict = {'soundfont': {}}
        dict['soundfont']['midipitch'] = mrk.next()+tr2
        sendEvent(1, dict, proc)
    ti1.changeTime(tempo)

ti1 = pattern(tempo, pit, [1,1,1,1])

ti1.start()
ti1.play()
